package com.jse.timer;

import java.text.ParseException;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import com.jse.log.Log;
import com.jse.log.Logs;

public class TaskService {

	Timer timer = new Timer();
	Log log=Logs.get();
	/**
	 * 每天清除缓存
	 */
	public void clearCache() {
		TimerTask task = new TimerTask() {
			@Override
			public void run() {
				log.info("cache clear success!");
			}
		};
		timer.schedule(task, new Date(), 86400000);
	}
	
	/**
	 * 执行任务
	 * @param task 任务
	 * @param date 执行的时间
	 * @param second 秒 执行间隔
	 */
	public void exec(TimerTask timerTask,Date date,int second) {
		timer.schedule(timerTask, date, second*1000);
	}
	
	/**
	 * 执行任务
	 * @param task 任务
	 * @param date 每天开始执行的时间
	 */
	public void exec(TimerTask timerTask,Date date) {
		timer.schedule(timerTask, date);
	}
	
	
	
	public static void main(String[] args) throws ParseException {
//		TaskService taskService=new TaskService();
//		Calendar calendar = Calendar.getInstance();
//        int year = calendar.get(Calendar.YEAR);
//        int month = calendar.get(Calendar.MONTH);
//        int day = calendar.get(Calendar.DAY_OF_MONTH);//每天
//        //定制每天的21:09:00执行，
//        calendar.set(year, month, day, 21, 9, 00);
//        taskService.exec(new TimerTask() {
//			@Override
//			public void run() {
//				log.info("执行测试");
//				
//			}
//		}, Times.parse("2017-11-22 16:26:59"));
//		log.error("xxxx");
	}
}
